WebWork 2 : Resources Available to Velocity Views
This page last changed on Dec 10, 2004 by sutter2k.
SummaryHere's the quick summary of the references available to Velocity templates that are kicked-off from WebWork:
Detail$actionInstanceVariable Each of your action class instance variables (for which you've written a getter method) are available in your Velocity template as $actionInstanceVariableName. In other words, if you have an instance variable in your Action class: public class ProcessEditTableRowAction extends ActionSupport { private String fooString; public String getFooString() { return fooString; } Then in your Velocity template you can retrieve the value of that String by simply refering to: $fooString But things can get weird is some circumstances. TODO: At least I think they can get weird. At one point, I remember having a problem with the lettercase of Velocity variable names and the corresponding getter methods that was being used to lookup the value. But I can't remember exactly how the problem manifested so can't provide an example. Need to do that. TODO: I'm curious what takes care of translating the $variableName references to method calls on the Action object's getters. Where does that happen?
$res The current HttpServletResponse created and managed by your Servlet environment (Tomcat, Resin, etc.).
$ognl.findValue("@com.acme.FooClass@FOO")
TODO: the original email detailing the above example used $value to refer to the OGNL tool, not $ognl. But the source indicates it's "$ognl" that's shared with the context. Which is right? $webwork A reference to the VelocityWebWorkUtil class. (API Docs) At the time of this writing, the API docs for this object are effectively blank, so if you really want to know how it works, be a Jedi and "use the source". (The CVS repository is browsable here: https://webwork.dev.java.net/source/browse/webwork/src/java) Tip: Mathew notes that the VelocityWebWorkUtil class can instantiate other objects for you. This, too, is very handy since Velocity is normally constrained to only the objects that have been explicitely shared with it's context (and not something you have control over when using Velocity templates kicked off by WebWork). To instantiate an object from a Velocity page (that's been kicked off by WebWork, of course) do this: #set($object = $webwork.bean("com.foo.ClassName"))
This technique can be particularly handy for grabbing a reference to one of the VelocityTools objects. (The VelocityTools are not included with WebWork, you'll need to go grab the lib and put it in your classpath if you want to use $webwork.bean() to grab references to the tool objects.) (Note: If you're rumaging through the source, the source-code for the $webwork.bean() method above is really in VelocityWebWorkUtil's parent class WebWorkUtil.)
#tag and #bodytag# Provides a way of using a JSP taglib from velocity. #tag( Text "name='title.edit'" )
provides a way to uses the <ww:text name="title.edit" /> tag from velocity. Note the <ww:text /> is probably not that useful from velocity since $action.getText('title.edit') |
Document generated by Confluence on Dec 14, 2004 16:36 |